function findCandy(cArr, pArr) {
    cArr.sort((a, b) => a - b)
    pArr.sort((a, b) => a - b)
    let pIndex = 0;
    for (let i = 0; i < cArr.length; i++) {
        if(cArr[i] >= pArr[pIndex]){
            pIndex++
        }
    }
    return pIndex
}

g = [1,2,3], s = [1,1]
console.log(findCandy(s,g))